package com.spzx.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.product.domian.Brand;
import com.spzx.product.mapper.BrandMapper;
import com.spzx.product.service.BrandService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {
    @Override
    public List<Brand> selectRoleList(Brand brand) {
        return baseMapper.selectRoleList(brand);
    }
    /*
        判断品牌名称是否唯一
     */
    @Override
    public boolean checkBrandNameUnique(Brand brand) {
        Long brandId = brand.getId()==null?-1L:brand.getId();
        Brand selectBrand = baseMapper.checkBrandNameUnique(brand.getName());
        if(selectBrand!=null && selectBrand.getId().longValue()!=brandId.longValue()){
            return false;
        }
        return true;
    }
    /*
        新增品牌
     */
    @Override
    public int insertBrand(Brand brand) {
        return baseMapper.insertBrand(brand);
    }

    @Override
    public int updateBrand(Brand brand) {

        return baseMapper.updateBrand(brand);
    }
}